package com.quanyan.stadium.service.commonComponent.impl;

import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.google.gson.Gson;
import com.quanyan.api.APIResponse;
import com.quanyan.club.entity.*;
import com.quanyan.club.entity.vo.resp.RespSearchActivity;
import com.quanyan.club.service.ClubOpenService;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.constants.Constants;
import com.quanyan.common.utils.ObjectUtil;
import com.quanyan.orderpay.request.ReqSysPayInfo;
import com.quanyan.orderpay.response.RespPayInfo;
import com.quanyan.orderpay.service.OrderPayService;
import com.quanyan.place.client.PlaceClient;
import com.quanyan.place.entity.PlaceDubboProvider;
import com.quanyan.place.entity.PlaceUnitDubboProvider;
import com.quanyan.place.entity.apiresp.RespCity;
import com.quanyan.place.entity.apiresp.RespCityInfos;
import com.quanyan.place.entity.apiresp.RespDistrict;
import com.quanyan.place.entity.vo.RespDistrictVo;
import com.quanyan.stadium.api.req.ReqLocation;
import com.quanyan.stadium.api.resp.RespStadiumDefaultConfig;
import com.quanyan.stadium.biz.redis.DefaultConfigCacheDao;
import com.quanyan.stadium.biz.redis.UserCenterCacheDao;
import com.quanyan.stadium.constants.GameConstants;
import com.quanyan.stadium.entity.TbGameBanner;
import com.quanyan.stadium.entity.TbGameBannerExample;
import com.quanyan.stadium.entity.TbGameCommonParameter;
import com.quanyan.stadium.entity.TbGameCommonParameterExample;
import com.quanyan.stadium.entity.vo.GameBanner;
import com.quanyan.stadium.entity.vo.PlaceInfo;
import com.quanyan.stadium.entity.vo.PlaceUnitInfo;
import com.quanyan.stadium.entity.vo.UserMedal;
import com.quanyan.stadium.mapper.TbGameBannerMapper;
import com.quanyan.stadium.mapper.TbGameCommonParameterMapper;
import com.quanyan.stadium.service.commonComponent.BaseService;
import com.quanyan.user.response.RespOpenUserMedal;
import com.quanyan.user.response.RespUserInfoBase;
import com.quanyan.user.response.RespUserInfoDetail;
import com.quanyan.user.serviceFacade.UserMedalServiceFacade;
import com.quanyan.user.serviceFacade.UserServiceFacade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.*;

/**
 * @author xiaoxiao
 * @date 16/4/11-14:42
 *
 * 该类存放一些公用方法,方便本模块中的方法使用,获取外部模块提供的方法,均从改模块出
 */

@Service("baseService")
public class BaseServiceImpl implements BaseService {

    private final static Logger logger = LoggerFactory.getLogger(BaseServiceImpl.class);

    private static final Gson gson = new Gson();

    @Autowired
    private TbGameBannerMapper tbGameBannerMapper;

    @Autowired
    private ClubOpenService clubOpenService;

    @Autowired
    private UserServiceFacade userServiceFacade;

    @Autowired
    private PlaceClient placeClient;

    @Autowired
    private TbGameCommonParameterMapper tbGameCommonParameterMapper;

    @Autowired
    private DefaultConfigCacheDao defaultConfigCacheDao;

    @Autowired
    private UserCenterCacheDao userCenterCacheDao;

    @Autowired
    private UserMedalServiceFacade userMedalServiceFacade;

    @Autowired
    OrderPayService orderPayService;

    @Override
    public RespStadiumDefaultConfig getStadiumDefaultConfig() {
        RespStadiumDefaultConfig respStadiumDefaultConfig = new RespStadiumDefaultConfig();
        TbGameCommonParameter config = this.queryTbGameCommonParameter(GameConstants.STADIUM_DEFAULT_GROUP_BASE_CONFIG_KEY, GameConstants.BASE_CONFIG_KEY_EXTEND_NAME);
        if (null!=config) {
            respStadiumDefaultConfig.setDesConfig(Arrays.asList(config.getParameterValue().split(";")));
        }
        TbGameBannerExample example = new TbGameBannerExample();
        TbGameBannerExample.Criteria criteria = example.createCriteria();
        criteria.andIsDeleteEqualTo(GameConstants.IS_NOT_DELETE);
        example.setOrderByClause("priority desc");
        List<TbGameBanner>  list = tbGameBannerMapper.selectByExample(example);
        if (null!=list && list.size()>0) {
            List<GameBanner> banners = new ArrayList<>();
            for (TbGameBanner tbGameBanner : list) {
                GameBanner gameBanner = new GameBanner();
                gameBanner.setName(tbGameBanner.getName());
                gameBanner.setDesc(tbGameBanner.getExtenName());
                gameBanner.setIcon(tbGameBanner.getIcon());
                gameBanner.setUrl(tbGameBanner.getReUrl());
                banners.add(gameBanner);
            }
            respStadiumDefaultConfig.setGameBanners(banners);
        }
        return respStadiumDefaultConfig;
    }

    @Override
    public APIResponse<List<GameBanner>> gameBanner(Integer cityId, Integer districtId) throws InvocationTargetException, IllegalAccessException {
        /*TbGameBannerExample example = new TbGameBannerExample();
        TbGameBannerExample.Criteria criteria = example.createCriteria();
        if (null != cityId) {
            criteria.andCityIdEqualTo(cityId);
        }
        if (null != districtId) {
            criteria.andDistrictIdEqualTo(districtId);
        }
        example.setOrderByClause("priority desc");
        List<TbGameBanner>  list = tbGameBannerMapper.selectByExample(example);

        if (null == list || list.size() < 1) {
            example.clear();
            TbGameBannerExample.Criteria criteriaNew = example.createCriteria();
            criteriaNew.andCityIdEqualTo(cityId);
            list = tbGameBannerMapper.selectByExample(example);
            if (null == list || list.size() < 1) {
                return APIResponse.returnSuccess(null);
            }
        }
        List<GameBanner> result = new ArrayList<>();
        for (TbGameBanner tbGameBanner : list) {
            GameBanner gameBanner = new GameBanner();
            BeanUtils.copyProperties(gameBanner, tbGameBanner);
            gameBanner.setIcon(tbGameBanner.getIcon());
            result.add(gameBanner);
        }*/
        List<GameBanner> result = new ArrayList<>();
        for (int i=0;i<1;i++) {
            GameBanner gameBanner = new GameBanner();
            gameBanner.setName("百灵鸟");
            gameBanner.setUrl("http://quncao.b0.upaiyun.com/club/activity/poster/tennis/tennis1.png");
            gameBanner.setIcon("http://quncao.b0.upaiyun.com/club/activity/poster/tennis/tennis1.png");
            gameBanner.setDistrictId(1);
            gameBanner.setCityId(1);
            gameBanner.setDesc("百灵鸟");
            result.add(gameBanner);
        }
        return APIResponse.returnSuccess(result);
    }

    @Override
    public RespCity getRespCityById(Integer cityId) {
        if (cityId == null || cityId < 1) {
            return null;
        }
        RespCity respCity = userCenterCacheDao.getRespCityById(cityId);
        if (null==respCity || respCity.getId()<1) {
            try {
                respCity = placeClient.getRespCityById(cityId);
                if (respCity!=null && respCity.getId()>0) {
                    userCenterCacheDao.putRespCityById(respCity);
                }
            }catch (Exception e){
                logger.error("调用场馆dubbo方法:getRespCityById,状态:失败!", e);
            }
        }
        return respCity;
    }

    @Override
    public List<RespDistrict> queryDistrictListByCityId(Integer cityId) {
        List<RespDistrict> result = new ArrayList<>();
        try {
            List<RespDistrictVo> temp = placeClient.getDistrictByCityId(cityId);
            if (null!=temp) {
                for (RespDistrictVo vo :temp) {
                    RespDistrict respDistrict = new RespDistrict();
                    BeanUtils.copyProperties(vo,respDistrict);
                    result.add(respDistrict);
                }
            }
        }catch (Exception e){
            logger.error("调用场馆dubbo方法:getDistrictByCityId,状态:失败!", e);
        }finally {
            return result;
        }
    }


    @Override
    public List<RespCityInfos> queryRespCityInfos() {
        List<RespCityInfos> result = new ArrayList<>();
        try {
            result = placeClient.getSysCityInfos();
        }catch (Exception e){
            result = null;
            logger.error("调用场馆dubbo方法:getSysCityInfos,状态:失败!", e);
        }finally {
            return result;
        }
    }

    /**
     * 根据场馆id获取下面可用场地集合
     *
     * */
    @Override
    public APIResponse<?> queryUsablePlaceUnits(Integer placeId) {
        List<PlaceUnitInfo> PlaceUnitInfoList = new ArrayList<>();
        if (!StringUtils.isEmpty(placeId) && placeId > 0) {
            try {
                List<Integer> placeIds = new ArrayList<>();
                placeIds.add(placeId);
                Map<Integer, PlaceInfo> placeMap =  this.queryPlaceInfoMsgList(placeIds);
                List<PlaceUnitDubboProvider> placeUnitDubboProviderList = placeClient.getPlaceUnitListByPlaceId(placeId);
                if (null != placeUnitDubboProviderList && placeUnitDubboProviderList.size() > 0){
                    for (PlaceUnitDubboProvider placeUnitDubboProvider : placeUnitDubboProviderList){
                        PlaceUnitInfo placeUnitInfo = new PlaceUnitInfo();
                        BeanUtils.copyProperties(placeUnitDubboProvider, placeUnitInfo);
                        placeUnitInfo.setUnitName(placeUnitDubboProvider.getName());
                        placeUnitInfo.setName(placeMap.get(placeId).getName());
                        PlaceUnitInfoList.add(placeUnitInfo);
                    }
                }
            }catch (Exception e){
                logger.error("调用场馆dubbo方法:getPlaceUnitListByPlaceId,状态:失败!", e);
            }
        }else {
            for (int i=1;i<=GameConstants.DEFAULT_PLACE_UNIT_NUM;i++) {
                int temp = GameConstants.DEFAULT_FIRST_PLACE_UNIT_ID + i;
                PlaceUnitInfo placeUnitInfo = new PlaceUnitInfo();
                placeUnitInfo.setPlaceUnitId(temp);
                placeUnitInfo.setUnitName(i+"号场");
                PlaceUnitInfoList.add(placeUnitInfo);
            }
        }

        return APIResponse.returnSuccess(PlaceUnitInfoList);
    }

    /**
     * 根据,城市id, 区域id获取下面的场馆基本对象
     */
    @Override
    public List<PlaceInfo> queryPlaceInfoByDistrictId(Integer cityId,Integer districtId) {
        List<PlaceInfo> placeInfos = new ArrayList<>();
        try {
            List<PlaceDubboProvider> placeDubboProviderList = placeClient.getPlaceListByCityIdOrDistrictId(cityId, districtId);
            if (null != placeDubboProviderList && placeDubboProviderList.size() >0 ){
                for (PlaceDubboProvider placeDubboProvider : placeDubboProviderList){
                    PlaceInfo placeInfo = new PlaceInfo();
                    BeanUtils.copyProperties(placeDubboProvider,placeInfo);
                    placeInfos.add(placeInfo);
                }
            }
        }catch (Exception e){
            logger.error("调用场馆dubbo方法:getPlaceListByCityIdOrDistrictId,状态:失败!", e);
        }
        return placeInfos;



    }

    @Override
    public List<PlaceInfo> queryPlaceInfoByDistrictId(Integer cityId, Integer districtId, Integer categoryId) {
        List<PlaceInfo> placeInfos = new ArrayList<>();
        try {
            List<PlaceDubboProvider> placeDubboProviderList = placeClient.getPlaceListByCityIdOrDistrictId(cityId, districtId, categoryId);
            if (null != placeDubboProviderList && placeDubboProviderList.size() >0 ){
                for (PlaceDubboProvider placeDubboProvider : placeDubboProviderList){
                    PlaceInfo placeInfo = new PlaceInfo();
                    BeanUtils.copyProperties(placeDubboProvider,placeInfo);
                    placeInfos.add(placeInfo);
                }
            }
        }catch (Exception e){
            logger.error("调用场馆dubbo方法:getPlaceListByCityIdOrDistrictId(存在categoryId),状态:失败!", e);
        }
        return placeInfos;
    }

    /**
     *  根据场地id集合获取场地的基本对象集合
     */
    @Override
    public Map<Integer, PlaceUnitInfo> queryPlaceUnitInfoMsgList(List<Integer> placeUnitIds) {
        Map<Integer, PlaceUnitInfo> map = new HashMap<>();
        /*try {
            Map<Integer,PlaceUnitDubboProvider> placeUnitDubboProviderMap = placeClient.getPlaceUnitListByPlaceUnitId(placeUnitIds);
            if (null != placeUnitDubboProviderMap && placeUnitDubboProviderMap.size() > 0){
                for (Map.Entry<Integer,PlaceUnitDubboProvider> entry : placeUnitDubboProviderMap.entrySet()){
                    PlaceUnitInfo placeUnitInfo = new PlaceUnitInfo();
                    BeanUtils.copyProperties(entry.getValue(), placeUnitInfo);
                    placeUnitInfo.setUnitName(entry.getValue().getName());
                    map.put(entry.getKey(), placeUnitInfo);
                }
            }
        }catch (Exception e){
            logger.error("调用场馆dubbo方法:getPlaceUnitListByPlaceUnitId,状态:失败!", e);
        }*/
        if (!StringUtils.isEmpty(placeUnitIds)) {
            for (int i=0;i<placeUnitIds.size();i++) {
                PlaceUnitInfo placeUnitInfo = new PlaceUnitInfo();
                placeUnitInfo.setPlaceUnitId(placeUnitIds.get(i));
                placeUnitInfo.setUnitName(placeUnitIds.get(i) - GameConstants.DEFAULT_FIRST_PLACE_UNIT_ID+"号场");
                map.put(placeUnitIds.get(i), placeUnitInfo);
            }
        }
        return map;
    }

    /**
     *  根据场馆id集合获取场馆的基本对象集合
     */
    @Override
    public Map<Integer, PlaceInfo> queryPlaceInfoMsgList(List<Integer> placeIds) {
        Map<Integer, PlaceInfo> map = new HashMap<>();
        try {
            Map<Integer,PlaceDubboProvider> placeDubboProviderMap = placeClient.getPlaceListByPlaceId(placeIds);
            if (null != placeDubboProviderMap && placeDubboProviderMap.size() > 0)
                for (Map.Entry<Integer, PlaceDubboProvider> entry : placeDubboProviderMap.entrySet()) {
                    PlaceInfo placeInfo = new PlaceInfo();
                    BeanUtils.copyProperties(entry.getValue(),placeInfo);
                    placeInfo.setDistrictName(entry.getValue().getDestrictName());
                    map.put(entry.getKey(),placeInfo);
                }
        }catch (Exception e){
            logger.error("调用场馆dubbo方法:getPlaceListByPlaceId,状态:失败!", e);
        }
        return map;
    }

    @Override
    public PageObj<List<RespClubBaseInfo>> queryClubMsgByKey(String key, Integer cityId, Integer districtId,
                                                             Integer pageNum, Integer pageSize) {
        PageObj<List<RespClubBaseInfo>> result = null;
        try{
            List<Integer> sportTypeIds = new ArrayList<>();
            sportTypeIds.add(GameConstants.CATEGORY_ID_BADMINTON);
            sportTypeIds.add(GameConstants.CATEGORY_ID_TENNIS);
            sportTypeIds.add(GameConstants.CATEGORY_ID_BASKETBALL);
            sportTypeIds.add(GameConstants.CATEGORY_ID_FOOTBALL);
            result = clubOpenService.getClubByName(key, sportTypeIds, cityId, districtId, pageNum, pageSize);
        }catch (Exception e) {
            result = PageObj.create(0, pageNum, pageSize, null);
            logger.error("调用俱乐部dubbo方法:getClubBaseInfoList,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public boolean isJoinedClub(Integer clubId, Integer uid) {
        RespIsClubMember result = null;
        try{
            result = clubOpenService.isClubMember(clubId, uid);
        }catch (Exception e) {
            result = new RespIsClubMember();
            logger.error("调用俱乐部dubbo方法:isClubMember,状态:失败!", e);
        }finally {
            if (result.isFlag()) {
                return true;
            }
            return false;
        }
    }

    @Override
    public Map<Integer, RespClubPlainInfo> queryClubMsg(List<Integer> clubs) {
        Map<Integer, RespClubPlainInfo> result = new HashMap<>();
        try{
            result = clubOpenService.getClubBaseInfoList(clubs);
        }catch (Exception e) {
            result = new HashMap<>();
            logger.error("调用俱乐部dubbo方法:getClubBaseInfoList,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public RespClubPlainInfo queryClubMsg(Integer clubId) {
        RespClubPlainInfo result = new RespClubPlainInfo();
        if (clubId == null) {
            return result;
        }
        List<Integer> clubs = new ArrayList<>();
        clubs.add(clubId);
        try{
            result = clubOpenService.getClubBaseInfoList(clubs).get(clubId);
        }catch (Exception e) {
            result = new RespClubPlainInfo();
            logger.error("调用俱乐部dubbo方法:getClubsTeamMembersId,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public Map<Integer, List<Integer>> queryClubIds(List<Integer> clubs) {
        Map<Integer, List<Integer>> result = new HashMap<>();
        if (null == clubs || clubs.size() < 1) {
            return result;
        }
        try{
            result = clubOpenService.getClubsTeamMembersId(clubs);
        }catch (Exception e) {
            result = new HashMap<>();
            logger.error("调用俱乐部dubbo方法:getClubsTeamMembersId,状态:失败!", e);
        }finally {
            return result;
        }
    }


    @Override
    public List<Integer> queryMyClubIds(Integer uid) {
        List<Integer> result = new ArrayList<>();
        try{
            if (null!=uid) {
                result = clubOpenService.getClubIds(uid);
            }
        }catch (Exception e) {
            result = new ArrayList<>();
            logger.error("调用俱乐部dubbo方法:getClubIds,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public int queryMyClubNumByCategoryId(Integer uid, Integer categoryId) {
        int result = 0;
        try{
            List<Integer> ids = new ArrayList<>();
            if (null!=uid) {
                ids = clubOpenService.getClubIds(uid, categoryId);
            }
            if (null != ids && ids.size() >0) {
                result = ids.size();
            }
        }catch (Exception e) {
            result = 0;
            logger.error("调用俱乐部dubbo方法获取栏目下的俱乐部:getClubIds,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public List<Integer> queryMyClubListByCategoryId(Integer uid, Integer categoryId) {
        List<Integer> result = null;
        try{
            if (null!=uid) {
                result = clubOpenService.getClubIds(uid, categoryId);
            }
        }catch (Exception e) {
            logger.error("调用俱乐部dubbo方法获取栏目下的俱乐部:getClubIds,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public Map<Integer, RespUserInfoBase> queryUserMsg(List<Integer> uIds) {
        Map<Integer, RespUserInfoBase> result = new HashMap<>();
        if (null == uIds || uIds.size() < 1) {
            return result;
        }
        try{
            result = userServiceFacade.batchQueryUserInfoToMap(uIds);
        }catch (Exception e) {
            result = new HashMap<>();
            logger.error("调用用户中心方法:batchQueryUserInfoToMap,状态:失败! ", e);
        }finally {
            return result;
        }
    }

    @Override
    public RespUserInfoDetail queryUserMsg(Integer uid) {
        RespUserInfoDetail result = null;
        if (null == uid) {
            return result;
        }
        try{
            APIResponse<RespUserInfoDetail> resultTemp = userServiceFacade.queryUserInfoDetail(uid);
            if (null!= resultTemp && null != resultTemp.getData()) {
                result =  resultTemp.getData();
                result.setHeight(result.getHeightDe());
                result.setWeight(result.getWeightDe());
                result.setLevel(result.getLevelDe());
            }
        }catch (Exception e) {
            logger.error("调用用户中心方法:queryUserInfo,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public RespUserInfoBase queryUserMsgByMobile(String mobile) {
        RespUserInfoBase result = new RespUserInfoBase();
        try{
            APIResponse resultTemp = userServiceFacade.queryUserInfoByPhone(mobile);
            if (null!= resultTemp && null != resultTemp.getData()) {
                result = (RespUserInfoBase) resultTemp.getData();
            }
        }catch (Exception e) {
            logger.error("调用用户中心方法:queryUserMsgByMobile,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public RespUserInfoBase queryUserMsgByPhone(String mobile) {
        RespUserInfoBase result = null;
        try{
            APIResponse resultTemp = userServiceFacade.queryUserInfoByPhone(mobile);
            if (null!= resultTemp && resultTemp.isRet() == true && null != resultTemp.getData()) {
                result = (RespUserInfoBase) resultTemp.getData();
            }
        }catch (Exception e) {
            logger.error("调用用户中心方法:queryUserMsgByMobile,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public List<TbGameCommonParameter> queryTbGameCommonParameterList(String paramGroupKey) {
        List<TbGameCommonParameter> result = defaultConfigCacheDao.getTbGameCommonParameterListMsgFromCache(paramGroupKey);
        if (result == null || result.size() < 1) {
            TbGameCommonParameterExample example = new TbGameCommonParameterExample();
            TbGameCommonParameterExample.Criteria criteria = example.createCriteria();
            criteria.andParameterGroupEqualTo(paramGroupKey);
            criteria.andIsDeleteEqualTo(GameConstants.IS_NOT_DELETE);
            result = tbGameCommonParameterMapper.selectByExample(example);
            defaultConfigCacheDao.initTbGameCommonParameterMsgToCache(paramGroupKey, result);
            return  result;
        }
        return result;
    }

    @Override
    public TbGameCommonParameter queryTbGameCommonParameter(String paramGroupKey, String paramKey) {
        List<TbGameCommonParameter> result = defaultConfigCacheDao.getTbGameCommonParameterListMsgFromCache(paramGroupKey);
        if (result == null || result.size() < 1) {
            TbGameCommonParameterExample example = new TbGameCommonParameterExample();
            TbGameCommonParameterExample.Criteria criteria = example.createCriteria();
            criteria.andParameterGroupEqualTo(paramGroupKey);
            criteria.andIsDeleteEqualTo(GameConstants.IS_NOT_DELETE);
            result = tbGameCommonParameterMapper.selectByExample(example);
            defaultConfigCacheDao.initTbGameCommonParameterMsgToCache(paramGroupKey, result);
        }
        if (ObjectUtil.isNotObjectEmpty(result)) {
            for (TbGameCommonParameter tbGameCommonParameter:result) {
                if (tbGameCommonParameter.getParameterKey().equals(paramKey)) {
                    return tbGameCommonParameter;
                }
            }
        }
        return null;
    }


    @Override
    public PageObj<List<RespClubActivity>> queryClubRecommendActivityPageObj() {
        PageObj<List<RespClubActivity>>  result = null;
        try{
            result = clubOpenService.selectActivityRecommend(null, null, 0, 20);
        }catch (Exception e) {
            result = PageObj.create(0, 0, 20, null);
            logger.error("调用俱乐部dubbo方法:selectActivityRecommend,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public APIResponse<PageObj<List<RespSearchActivity>>> queryClubRecommendActivity(Integer uid, ReqLocation reqLocation) {
        APIResponse<PageObj<List<RespSearchActivity>>>  result = null;
        try{
            result = clubOpenService.queryActivityListByCondition(uid, reqLocation.getLat(), reqLocation.getLng(), 0, 20);
        }catch (Exception e) {
            logger.error("调用俱乐部dubbo方法:selectActivityRecommend,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public List<UserMedal> getUserMedalList(Integer gameCategoryId,Integer uid, Integer medalNum) {
        List<UserMedal>  medalList = new ArrayList<>();
        if (null == gameCategoryId || null == uid || null == medalNum){
            return medalList;
        }
        try {
            List<RespOpenUserMedal> userMedalList = userMedalServiceFacade.getUserMedalList(gameCategoryId,uid,medalNum);
            if (null != userMedalList && userMedalList.size() > 0){
                for (RespOpenUserMedal respOpenUserMedal : userMedalList){
                    UserMedal userMedal = new UserMedal();
                    BeanUtils.copyProperties(respOpenUserMedal,userMedal);
                    if (respOpenUserMedal.getMedalStartLevel() == 0){
                        userMedal.setGet(false);
                        userMedal.setIcon(respOpenUserMedal.getEmptyIcon());
                    }
                    medalList.add(userMedal);
                }
            }
        }catch (Exception e){
            logger.error("调用用户中心dubbo方法:userMedalServiceFacade.getUserMedalList,状态:失败!", e);
        }
        return medalList;
    }

    @Override
    public boolean isSportClubMember(Integer uid, Integer gameCategoryId) {
        boolean isSportClubMember = false;
        try {
            isSportClubMember = clubOpenService.isSportClubMember(uid,gameCategoryId);
        }catch (Exception e){
            logger.error("调用俱乐部dubbo方法:clubOpenService.isSportClubMember,状态:失败!",e);
        }
        return isSportClubMember;
    }

    @Override
    public boolean isSportClubAdmin(Integer uid, Integer gameCategoryId) {
        boolean isSportClubAdmin = false;
        try {
            isSportClubAdmin = clubOpenService.isSportClubAdmin(uid,gameCategoryId);
        }catch (Exception e){
            logger.error("调用俱乐部dubbo方法:clubOpenService.isSportClubAdmin,状态:失败!",e);
        }
        return isSportClubAdmin;
    }

    @Override
    public List<Integer> getMyManageClubIds(Integer uid) {
        List<Integer> result = new ArrayList<>();
        try{
            if (null!=uid) {
                List<RespClubOpenInfo> temp = clubOpenService.getMyManageClubList(uid);
                if (CollectionUtils.isNotEmpty(temp)) {
                    for (RespClubOpenInfo club : temp) {
                        result.add(club.getClubId());
                    }
                }
            }
        }catch (Exception e) {
            result = new ArrayList<>();
            logger.error("调用俱乐部dubbo方法:getMyManageClubList,状态:失败!", e);
        }finally {
            return result;
        }
    }


    @Override
    public List<Integer> getManageByClubId(Integer clubId) {
        List<Integer> result = new ArrayList<>();
        try{
            if (null!=clubId) {
                List<RespClubMemberBaseInfo> temp = clubOpenService.getClubAdmins(clubId);
                if (CollectionUtils.isNotEmpty(temp)) {
                    for (RespClubMemberBaseInfo user : temp) {
                        result.add(user.getUid());
                    }
                }
            }
        }catch (Exception e) {
            result = new ArrayList<>();
            logger.error("调用俱乐部dubbo方法:getClubAdmins,状态:失败!", e);
        }finally {
            return result;
        }
    }

    @Override
    public String getUserQRCode(Integer uid) {
        String userQRCode = "";
        try {
            userQRCode = userServiceFacade.getUserQRCode(uid);
        }catch (Exception e){
            logger.error("调用用户中心dubbo方法：userServiceFacade.getUserQRCode，状态:失败!",e);
        }
        return userQRCode;
    }

    @Override
    public RespDistrict getRespDistrictByLatAndLng(double lat, double lng) {
        RespDistrict respDistrict = new RespDistrict();
        try {
            respDistrict = placeClient.getRespDistrict(lat, lng);
        }catch (Exception e){
            logger.error("调用用户中心dubbo方法：placeClient.getRespDistrict，状态:失败!",e);
        }
        return respDistrict;
    }

    @Override
    public List<Integer> getClubIdsByUid(Integer uid, Integer categoryId) {
        List<Integer> clubIds = new ArrayList<>();
        try {
            clubIds = clubOpenService.getClubIds(uid, categoryId);
        }catch (Exception e){
            logger.error("调用俱乐部dubbo方法：clubOpenService.getClubIds，状态:失败!", e);
        }
        return clubIds;
    }

    @Override
    public List<RespClubPlainInfo> getMyManageClubs(int uid) {
        List<RespClubPlainInfo> clubIds = new ArrayList<>();
        try {
            clubIds = clubOpenService.getMyManageClubs(uid);
        }catch (Exception e){
            logger.error("调用俱乐部dubbo方法：clubOpenService.getMyManageClubs，状态:失败!", e);
        }
        return clubIds;
    }

    @Override
    public List<RespPayInfo> queryPayTypeList() {
        List<RespPayInfo> payInfos = null;
        ReqSysPayInfo reqPayInfo = new ReqSysPayInfo();
        reqPayInfo.setSourceBusinessId(Constants.STADIUM_SYSTEM_CODE);
        reqPayInfo.setSourceSystemId(Constants.STADIUM_GAME_SIGN_BUSINESS_CODE);
        payInfos = orderPayService.selectEnablePayInfos(reqPayInfo).getData();
        if (org.apache.commons.collections.CollectionUtils.isEmpty(payInfos)) {
            Integer[] payIds = {GameConstants.PAY_WAY_ALIPAY, GameConstants.PAY_WAY_WEICHAT,
                    GameConstants.PAY_WAY_FOR_AGES};
            List<Integer> payIdList = Arrays.asList(payIds);
            reqPayInfo.setPayIds(payIdList);
            payInfos = orderPayService.applyEnablePayInfos(reqPayInfo).getData();
        }
        logger.info("查询赛事系统报名支持的支付方式={}", gson.toJson(payInfos));
        return payInfos;
    }
}
